package com.woniu.elderly.serve.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfiguration {
    //定义消息序列号格式
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    //定义队列
    @Bean
    public Queue queuesendorder(){
        return new Queue("queuesendorder");
    }

    //topics模式，定义topic类型的交换机
    @Bean
    public TopicExchange topicexchange(){
        return new TopicExchange("topicexchange");
    }

    //将队列绑定到交换机
    @Bean
    public Binding bindingqueuesendordertotopicexchange(Queue queuesendorder, TopicExchange topicexchange){
        return BindingBuilder.bind(queuesendorder).to(topicexchange).with("#.sendorder.#");
    }
}
